<?php
/**
 *
 */
class summary extends CI_Controller {

  public function __construct() {
    parent::__construct();
    $this->load->model('M_summary');
    $this->load->model('Util');
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('session');
    if($this->session->userdata('username')==null){
      redirect('/login');
    }
  }
  public function index(){
    $this->load->view('summary');
  }
  public function summary_add(){
    $this->load->view('summary_add');
  }
  public function admin_summary_add(){
    $this->load->view('admin_summary_add');
  }
  public function summaryadd(){
      $option = array(
        'shopid'         => $_POST['shopid'],
        'bid'            => $_POST['bid'],
        'content'        => $_POST['content'],
        'getboss'        => $_POST['getboss'],
        'inshop'         => $_POST['inshop'],
        'joinv'          => $_POST['joinv'],
        'meet'           => $_POST['meet'],
        'outcount'       => $_POST['outcount'],
        'skcount'        => $_POST['skcount'],
        'outday'         => $_POST['outday'],
        'pass'           => $_POST['pass'],
        'seeboss'        => $_POST['seeboss'],
        'sellcar'        => $_POST['sellcar'],
        'tecount'        => $_POST['tecount'],
        'emid'           => $this->session->userdata('username')
      );
      echo $this->M_summary->summaryadd($option);
  }
  public function admin_summaryadd(){
      $option = array(
        'shopid'         => $_POST['shopid'],
        'bid'            => $_POST['bid'],
        'content'        => $_POST['content'],
        'getboss'        => $_POST['getboss'],
        'inshop'         => $_POST['inshop'],
        'joinv'          => $_POST['joinv'],
        'meet'           => $_POST['meet'],
        'outcount'       => $_POST['outcount'],
        'skcount'        => $_POST['skcount'],
        'outday'         => $_POST['outday'],
        'pass'           => $_POST['pass'],
        'seeboss'        => $_POST['seeboss'],
        'sellcar'        => $_POST['sellcar'],
        'tecount'        => $_POST['tecount'],
        'emid'           => $_POST['emid']
      );
      echo $this->M_summary->summaryadd($option);
  }
  public function summaryadd_t2(){
      $option = array(
        'emid'           => $this->session->userdata('username'),
        'bid'          => $_POST['bid'],
        'content'      => $_POST['content'],
        'inshop'       => $_POST['inshop'],
        'outday'       => $_POST['outday'],
        'seeboss'      => $_POST['seeboss'],
        'getboss'      => $_POST['getboss'],
        'tecount'      => $_POST['tecount'],
        'skcount'      => $_POST['skcount'],
        'outcount'     => $_POST['outcount'],
        'singledo'     => $_POST['singledo'],
        'singlefuck'   => $_POST['singlefuck'],
        'joinv'        => $_POST['joinv'],
        'sellcar'      => $_POST['sellcar'],
        'meet'         => $_POST['meet'],
        'pass'         => $_POST['pass']
      );
      echo $this->M_summary->summaryadd_t2($option);
  }
  public function admin_summaryadd_t2(){
      $option = array(
        'emid'         => $_POST['emid'],
        'bid'          => $_POST['bid'],
        'content'      => $_POST['content'],
        'inshop'       => $_POST['inshop'],
        'outday'       => $_POST['outday'],
        'seeboss'      => $_POST['seeboss'],
        'getboss'      => $_POST['getboss'],
        'tecount'      => $_POST['tecount'],
        'skcount'      => $_POST['skcount'],
        'outcount'     => $_POST['outcount'],
        'singledo'     => $_POST['singledo'],
        'singlefuck'   => $_POST['singlefuck'],
        'joinv'        => $_POST['joinv'],
        'sellcar'      => $_POST['sellcar'],
        'meet'         => $_POST['meet'],
        'pass'         => $_POST['pass']
      );
      echo $this->M_summary->summaryadd_t2($option);
  }
  public function summaryadd_t3(){
      $option = array(
        'emid'          => $this->session->userdata('username'),
        'content'       => $_POST['content'],
        'zone'          => $_POST['content'],
        'outday'        => $_POST['outday'],
        'runshop'       => $_POST['runshop'],
        'meetcount'     => $_POST['meetcount'],
        'shopinfocount' => $_POST['shopinfocount'],
        'bfshop'        => $_POST['bfshop'],
        'ysshop'        => $_POST['ysshop'],
        'ysgz'          => $_POST['ysgz'],
        'czshop'        => $_POST['czshop'],
        'czyj'          => $_POST['czyj'],
        'shopinfo'      => $_POST['shopinfo'],
        'newboss'       => $_POST['newboss']
      );
      echo $this->M_summary->summaryadd_t3($option);
  }
  public function admin_summaryadd_t3(){
      $option = array(
        'emid'          => $_POST['emid'],
        'content'       => $_POST['content'],
        'zone'          => $_POST['content'],
        'outday'        => $_POST['outday'],
        'runshop'       => $_POST['runshop'],
        'meetcount'     => $_POST['meetcount'],
        'shopinfocount' => $_POST['shopinfocount'],
        'bfshop'        => $_POST['bfshop'],
        'ysshop'        => $_POST['ysshop'],
        'ysgz'          => $_POST['ysgz'],
        'czshop'        => $_POST['czshop'],
        'czyj'          => $_POST['czyj'],
        'shopinfo'      => $_POST['shopinfo'],
        'newboss'       => $_POST['newboss']
      );
      echo $this->M_summary->summaryadd_t3($option);
  }
  public function summary_mylist(){
    $this->load->library('pagination');
    $page = 0;
    $offset = 0;
    $per_page = 10;
    $year = date('Y');
    $month = date('m');
    if(!empty($_GET['per_page'])){
      $page = $_GET['per_page'];
      $offset = ($page-1)*$per_page;
    }
    if(!empty($_GET['year'])){
      $year = $_GET['year'];
    }
    if(!empty($_GET['month'])){
      $month = $_GET['month'];
    }
    $result = $this->M_summary->getMySummarylist($this->session->userdata('username'),$per_page,$offset);
    // if(!empty($_GET['search'])){
    //   $result = $this->M_summary->getBrand($_GET['search'],$per_page,$offset);
    // }
    $config['base_url']=site_url('summary/summary_mylist');
    $config['total_rows'] = $result['total'];
    $config['per_page'] = $per_page;
    $this->pagination->initialize($config);
    $data['summarylist'] = $result['summarylist'];
    $data['pager'] = $this->pagination->create_links();
    $this->load->view('summary_mylist',$data);
    // echo $result['sql'];
  }
  public function summarylist(){
    $this->load->library('pagination');
    $page = 0;
    $offset = 0;
    $per_page = 15;
    if(!empty($_GET['per_page'])){
      $page = $_GET['per_page'];
      $offset = ($page-1)*$per_page;
    }
    $result = $this->M_summary->getSummarylist($per_page,$offset);
    if(!empty($_GET['search'])){
      $result = $this->M_summary->getSummarySelect($_GET['search'],$per_page,$offset);
    }
    $config['base_url']=site_url('summary/summarylist');
    $config['total_rows'] = $result['total'];
    $config['per_page'] = $per_page;
    $this->pagination->initialize($config);
    $data['summarylist'] = $result['summarylist'];
    $data['pager'] = $this->pagination->create_links();
    $this->load->view('summarylist',$data);
  }
  public function summarylist_t2(){
    $this->load->library('pagination');
    $page = 0;
    $offset = 0;
    $per_page = 10;
    if(!empty($_GET['per_page'])){
      $page = $_GET['per_page'];
      $offset = ($page-1)*$per_page;
    }
    $result = $this->M_summary->getSummarylist_t2($per_page,$offset);
    if(!empty($_GET['search'])){
      $result = $this->M_summary->getSummarySelect_t2($_GET['search'],$per_page,$offset);
    }
    $config['base_url']=site_url('summary/summarylist_t2');
    $config['total_rows'] = $result['total'];
    $config['per_page'] = $per_page;
    $this->pagination->initialize($config);
    $data['summarylist'] = $result['summarylist'];
    $data['pager'] = $this->pagination->create_links();
    $this->load->view('summarylist_t2',$data);
  }
  public function summarylist_t3(){
    $this->load->library('pagination');
    $page = 0;
    $offset = 0;
    $per_page = 10;
    if(!empty($_GET['per_page'])){
      $page = $_GET['per_page'];
      $offset = ($page-1)*$per_page;
    }
    $result = $this->M_summary->getSummarylist_t3($per_page,$offset);
    if(!empty($_GET['search'])){
      $result = $this->M_summary->getSummarySelect_t3($_GET['search'],$per_page,$offset);
    }
    $config['base_url']=site_url('summary/summarylist_t3');
    $config['total_rows'] = $result['total'];
    $config['per_page'] = $per_page;
    $this->pagination->initialize($config);
    $data['summarylist'] = $result['summarylist'];
    $data['pager'] = $this->pagination->create_links();
    $this->load->view('summarylist_t3',$data);
  }
  public function getsummarybyid(){
    if(!empty($_GET['id'])){
      $result = $this->M_summary->getSummarybyid($_GET['id']);
      print_r(json_encode($result[0]));
    }
  }
  public function getsummarybyid_t2(){
    if(!empty($_GET['id'])){
      $result = $this->M_summary->getSummarybyid_t2($_GET['id']);
      print_r(json_encode($result[0]));
    }
  }
  public function getsummarybyid_t3(){
    if(!empty($_GET['id'])){
      $result = $this->M_summary->getSummarybyid_t3($_GET['id']);
      print_r(json_encode($result[0]));
    }
  }
  public function summaryupdate_t1(){
      $option = array(
        'id'             => $_POST['id'],
        'shopid'         => $_POST['shopid'],
        'bid'            => $_POST['bid'],
        'content'        => $_POST['content'],
        'getboss'        => $_POST['getboss'],
        'inshop'         => $_POST['inshop'],
        'joinv'          => $_POST['joinv'],
        'meet'           => $_POST['meet'],
        'outcount'       => $_POST['outcount'],
        'skcount'        => $_POST['skcount'],
        'outday'         => $_POST['outday'],
        'pass'           => $_POST['pass'],
        'seeboss'        => $_POST['seeboss'],
        'sellcar'        => $_POST['sellcar'],
        'tecount'        => $_POST['tecount'],
        'emid'           => $_POST['emid']
      );
      echo $this->M_summary->summaryupdate_t1($option);
  }
  public function summaryupdate_t2(){
      $option = array(
        'id'             => $_POST['id'],
        'bid'            => $_POST['bid'],
        'content'        => $_POST['content'],
        'getboss'        => $_POST['getboss'],
        'inshop'         => $_POST['inshop'],
        'joinv'          => $_POST['joinv'],
        'meet'           => $_POST['meet'],
        'outcount'       => $_POST['outcount'],
        'skcount'        => $_POST['skcount'],
        'outday'         => $_POST['outday'],
        'singledo'       => $_POST['singledo'],
        'singlefuck'     => $_POST['singlefuck'],
        'pass'           => $_POST['pass'],
        'seeboss'        => $_POST['seeboss'],
        'sellcar'        => $_POST['sellcar'],
        'tecount'        => $_POST['tecount'],
        'emid'           => $_POST['emid']
      );
      echo $this->M_summary->summaryupdate_t2($option);
  }
  public function summaryupdate_t3(){
      $option = array(
        'emid'          => $_POST['emid'],
        'content'       => $_POST['content'],
        'zone'          => $_POST['zone'],
        'outday'        => $_POST['outday'],
        'runshop'       => $_POST['runshop'],
        'meetcount'     => $_POST['meetcount'],
        'shopinfocount' => $_POST['shopinfocount'],
        'bfshop'        => $_POST['bfshop'],
        'ysshop'        => $_POST['ysshop'],
        'ysgz'          => $_POST['ysgz'],
        'czshop'        => $_POST['czshop'],
        'czyj'          => $_POST['czyj'],
        'shopinfo'      => $_POST['shopinfo'],
        'newboss'       => $_POST['newboss'],
        'id'            => $_POST['id']
      );
      echo $this->M_summary->summaryupdate_t3($option);
  }
  public function summarydelete_t1(){
    if(!empty($_GET['id'])){
      $result = $this->M_summary->summarydelete_t1($_GET['id']);
      if($result>0){
        echo '删除成功';
      }else{
        echo '删除失败，要删除的记录不存在,请刷新页面后重试';
      }
    }else{
      echo 'fail';
    }
  }
  public function summarydelete_t2(){
    if(!empty($_GET['id'])){
      $result = $this->M_summary->summarydelete_t2($_GET['id']);
      if($result>0){
        echo '删除成功';
      }else{
        echo '删除失败，要删除的记录不存在,请刷新页面后重试';
      }
    }else{
      echo 'fail';
    }
  }
  public function summarydelete_t3(){
    if(!empty($_GET['id'])){
      $result = $this->M_summary->summarydelete_t3($_GET['id']);
      if($result>0){
        echo '删除成功';
      }else{
        echo '删除失败，要删除的记录不存在,请刷新页面后重试';
      }
    }else{
      echo 'fail';
    }
  }
  //导出员工总结
  public function summaryexcel(){
        $maxday='';
        $minday='';
        $emid='';
        $bid='';
        if(isset($_GET['maxday']) && isset($_GET['minday'])){
          $maxday = $_GET['maxday'];
          $minday = $_GET['minday'];
        }
        if(isset($_GET['emid'])&&$_GET['emid']!=''){
          $emid = $_GET['emid'];
          $emid = ' and summary.emid IN ('.$emid.')';
        }
        if(isset($_GET['bid'])&&$_GET['bid']!=''){
          $bid = $_GET['bid'];
          $bid = ' and summary.bid IN ('.$bid.')';
        }
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename='员工总结.csv'");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0'); header('Pragma:public');
        $str = "品牌,日期,姓名,店铺,考核内容/工作内容(地名+行程主题)+同行人,下店天数,出差天数,见终端客人/老板娘,成交终端客人/老板娘,终端销售业绩,收款业绩,出货业绩,考核过关人数/加微信,卖卡数量/拜访数量,会议铺垫/收集资料,备注\n";
        echo $str;
        $emm=2;
        $emk=2;
        $bm=2;
        $bk=2;
        $i=2;
        $SUM=array();
        $count = 1000;
        $offset = 0;
        $emname = '';
        $bname = '';
        $result = $this->M_summary->getemSummary($emid,$bid,$maxday,$minday,$count,$offset);
        while($result['row']>0) {
          $result = $this->M_summary->getemSummary($emid,$bid,$maxday,$minday,$count,$offset);
          foreach ($result['result'] as $shop) {
            $flagemname = 0;
            //员工合计
            if($emname=='')$emname=$shop['emname'];
            if($bname=='')$bname=$shop['bname'];
            if($emname!=$shop['emname']){
              $SUM[$i]=$i;
              $emm--;
              $str = "".$bname.",合计,".$emname.", , ,=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                      "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                      "=SUM(O".$emk.":O".$emm."), \n";
              echo $str;
              $i++;
              $emm+=2;
              $emk=$emm;
              $emname = $shop['emname'];
              $flagemname = 1;
            }
            //品牌总计
            if($bname!=$shop['bname']){
              if($flagemname == 0){
                $SUM[$i]=$i;
                $emm--;
                $str = "".$bname.",合计,".$emname.", , ,=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                        "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                        "=SUM(O".$emk.":O".$emm."), \n";
                echo $str;
                $i++;
                $emm+=2;
                $emk=$emm;
                $emname = $shop['emname'];
                $flagemname = 1;
              }
              $str = " ,总计, , , ,=SUM(".$this->Util->CsvSum("F",$SUM)."),=SUM(".$this->Util->CsvSum("G",$SUM)."),=SUM(".$this->Util->CsvSum("H",$SUM)."),=SUM(".$this->Util->CsvSum("I",$SUM)."),".
                      "=SUM(".$this->Util->CsvSum("J",$SUM)."),=SUM(".$this->Util->CsvSum("K",$SUM)."),=SUM(".$this->Util->CsvSum("L",$SUM)."),=SUM(".$this->Util->CsvSum("M",$SUM)."),=SUM(".$this->Util->CsvSum("N",$SUM)."),".
                      "=SUM(".$this->Util->CsvSum("O",$SUM)."), \n";
              echo $str;
              $i++;
              $emm++;
              $emk++;
              $SUM=array();
              $bname = $shop['bname'];
            }
            $emm++;

            $str = $shop['bname'].",".$shop['addday'].",".$shop['emname'].",".$shop['shopname'].",".$shop['content'].",".$shop['inshop'].",".
                    $shop['outday'].",".$shop['seeboss'].",".$shop['getboss'].",".$shop['tecount'].",".$shop['skcount'].",".$shop['outcount'].",".
                    $shop['joinv'].",".$shop['sellcar'].",".$shop['meet'].",".$shop['pass']."\n";
            echo $str;
            $i++;
          }
          $offset +=$count;
        }
        if($i!=2){
          $emm--;
          $SUM[$i]=$i;
          $str = "".$bname.",合计,".$emname.", , ,=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                  "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                  "=SUM(O".$emk.":O".$emm."), \n";
          echo $str;
          $str = " ,总计, , , ,=SUM(".$this->Util->CsvSum("F",$SUM)."),=SUM(".$this->Util->CsvSum("G",$SUM)."),=SUM(".$this->Util->CsvSum("H",$SUM)."),=SUM(".$this->Util->CsvSum("I",$SUM)."),".
                  "=SUM(".$this->Util->CsvSum("J",$SUM)."),=SUM(".$this->Util->CsvSum("K",$SUM)."),=SUM(".$this->Util->CsvSum("L",$SUM)."),=SUM(".$this->Util->CsvSum("M",$SUM)."),=SUM(".$this->Util->CsvSum("N",$SUM)."),".
                  "=SUM(".$this->Util->CsvSum("O",$SUM)."), \n";
          echo $str;
          }
      }

  public function summaryexcel_t2(){
        $maxday='';
        $minday='';
        $emid='';
        $bid='';
        if(isset($_GET['maxday']) && isset($_GET['minday'])){
          $maxday = $_GET['maxday'];
          $minday = $_GET['minday'];
        }
        if(isset($_GET['emid'])&&$_GET['emid']!=''){
          $emid = $_GET['emid'];
          $emid = ' and summary_t2.emid IN ('.$emid.')';
        }
        if(isset($_GET['bid'])&&$_GET['bid']!=''){
          $bid = $_GET['bid'];
          $bid = ' and summary_t2.bid IN ('.$bid.')';
        }
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename='员工总结 - 市场讲师监督表.csv'");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0'); header('Pragma:public');
        $str = "品牌,日期,姓名,考核内容/工作内容,下店天数,出差天数,见终端客人/老板娘,成交终端客人/老板娘,终端销售业绩,个人操作项目,个人消耗业绩,收款业绩,出货业绩,考核过关人数/加微信,卖卡数量/拜访数量,会议铺垫/收集资料,备注\n";
        echo $str;
        $emm=2;
        $emk=2;
        $bm=2;
        $bk=2;
        $i=2;
        $SUM=array();
        $count = 1000;
        $offset = 0;
        $emname = '';
        $bname = '';
        $result = $this->M_summary->getemSummary_t2($emid,$bid,$maxday,$minday,$count,$offset);
        while($result['row']>0) {
          $result = $this->M_summary->getemSummary_t2($emid,$bid,$maxday,$minday,$count,$offset);
          foreach ($result['result'] as $shop) {
            $flagemname = 0;
            //员工合计
            if($emname=='')$emname=$shop['emname'];
            if($bname=='')$bname=$shop['bname'];
            if($emname!=$shop['emname']){
              $SUM[$i]=$i;
              $emm--;
              $str = "".$bname.",合计,".$emname.", ,=SUM(E".$emk.":E".$emm."),=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                      "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                      "=SUM(O".$emk.":O".$emm."),=SUM(P".$emk.":P".$emm."), \n";
              echo $str;
              $i++;
              $emm+=2;
              $emk=$emm;
              $emname = $shop['emname'];
              $flagemname = 1;
            }
            //品牌总计
            if($bname!=$shop['bname']){
              if($flagemname == 0){
                $SUM[$i]=$i;
                $emm--;
                $str = "".$bname.",合计,".$emname.", ,=SUM(E".$emk.":E".$emm."),=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                        "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                        "=SUM(O".$emk.":O".$emm."),=SUM(P".$emk.":P".$emm."), \n";
                echo $str;
                $i++;
                $emm+=2;
                $emk=$emm;
                $emname = $shop['emname'];
                $flagemname = 1;
              }
              $str = " ,总计, , ,=SUM(".$this->Util->CsvSum("E",$SUM).") ,=SUM(".$this->Util->CsvSum("F",$SUM)."),=SUM(".$this->Util->CsvSum("G",$SUM)."),=SUM(".$this->Util->CsvSum("H",$SUM)."),=SUM(".$this->Util->CsvSum("I",$SUM)."),".
                      "=SUM(".$this->Util->CsvSum("J",$SUM)."),=SUM(".$this->Util->CsvSum("K",$SUM)."),=SUM(".$this->Util->CsvSum("L",$SUM)."),=SUM(".$this->Util->CsvSum("M",$SUM)."),=SUM(".$this->Util->CsvSum("N",$SUM)."),".
                      "=SUM(".$this->Util->CsvSum("O",$SUM)."),=SUM(".$this->Util->CsvSum("P",$SUM)."),\n";
              echo $str;
              $i++;
              $emm++;
              $emk++;
              $SUM=array();
              $bname = $shop['bname'];
            }
            $emm++;

            $str = $shop['bname'].",".$shop['addday'].",".$shop['emname'].",".$shop['content'].",".$shop['inshop'].",".
                    $shop['outday'].",".$shop['seeboss'].",".$shop['getboss'].",".$shop['singledo'].",".$shop['singlefuck'].",".$shop['tecount'].",".$shop['skcount'].",".$shop['outcount'].",".
                    $shop['joinv'].",".$shop['sellcar'].",".$shop['meet'].",".$shop['pass']."\n";
            echo $str;
            $i++;
          }
          $offset +=$count;
        }
        if($i!=2){
          $emm--;
          $SUM[$i]=$i;
          $str = "".$bname.",合计,".$emname.", ,=SUM(E".$emk.":E".$emm."),=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                  "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                  "=SUM(O".$emk.":O".$emm."),=SUM(P".$emk.":P".$emm."), \n";
          echo $str;
          $str = " ,总计, , ,=SUM(".$this->Util->CsvSum("E",$SUM).") ,=SUM(".$this->Util->CsvSum("F",$SUM)."),=SUM(".$this->Util->CsvSum("G",$SUM)."),=SUM(".$this->Util->CsvSum("H",$SUM)."),=SUM(".$this->Util->CsvSum("I",$SUM)."),".
                  "=SUM(".$this->Util->CsvSum("J",$SUM)."),=SUM(".$this->Util->CsvSum("K",$SUM)."),=SUM(".$this->Util->CsvSum("L",$SUM)."),=SUM(".$this->Util->CsvSum("M",$SUM)."),=SUM(".$this->Util->CsvSum("N",$SUM)."),".
                  "=SUM(".$this->Util->CsvSum("O",$SUM)."),=SUM(".$this->Util->CsvSum("P",$SUM)."),\n";
          echo $str;
          }
      }

  public function summaryexcel_t3(){
        $maxday='';
        $minday='';
        $emid='';
        if(isset($_GET['maxday']) && isset($_GET['minday'])){
          $maxday = $_GET['maxday'];
          $minday = $_GET['minday'];
        }
        if(isset($_GET['emid'])&&$_GET['emid']!=''){
          $emid = $_GET['emid'];
          $emid = ' and summary_t3.emid IN ('.$emid.')';
        }
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename='员工总结 - 拓展部考勤统计表.csv'");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0'); header('Pragma:public');
        $str = "日期,姓名,区域,行程内容,出差天数,跑店天数,会议场次,收集店面信息数量,拜访店面数量,有效店面数量,有效工资(有效拜访达6家),成交店面数量,成交业绩,成交店名+品牌+款项名称,新店老板娘和美容师总人数\n";
        echo $str;
        $emm=2;
        $emk=2;
        $i=2;
        $SUM=array();
        $count = 1000;
        $offset = 0;
        $emname = '';
        $result = $this->M_summary->getemSummary_t3($emid,$maxday,$minday,$count,$offset);
        while($result['row']>0) {
          $result = $this->M_summary->getemSummary_t3($emid,$maxday,$minday,$count,$offset);
          foreach ($result['result'] as $shop) {
            $flagemname = 0;
            //员工合计
            if($emname=='')$emname=$shop['emname'];
            if($emname!=$shop['emname']){
              $SUM[$i]=$i;
              $emm--;
              $str = "合计,".$emname.", , , ,=SUM(E".$emk.":E".$emm."),=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                      "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."), ,".
                      "=SUM(O".$emk.":O".$emm."), , \n";
              echo $str;
              $i++;
              $emm+=2;
              $emk=$emm;
              $emname = $shop['emname'];
              $flagemname = 1;
            }
            $emm++;

            $str = $shop['addday'].",".$shop['emname'].",".$shop['zone'].",".$shop['content'].",".$shop['outday'].",".
                    $shop['runshop'].",".$shop['meetcount'].",".$shop['shopinfocount'].",".$shop['bfshop'].",".$shop['ysshop'].",".$shop['ysgz'].",".$shop['czshop'].",".$shop['czyj'].",".
                    $shop['shopinfo'].",".$shop['newboss']."\n";
            echo $str;
            $i++;
          }
          $offset +=$count;
        }
        if($i!=2){
          $emm--;
          $SUM[$i]=$i;
          $str = "合计,".$emname.", , , ,=SUM(E".$emk.":E".$emm."),=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                  "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."), ,".
                  "=SUM(O".$emk.":O".$emm."), , \n";
          echo $str;
          }
      }

  public function allsummaryexcel(){
        header("Content-type:text/csv");
        header("Content-Disposition:attachment;filename='hello.csv'");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0'); header('Pragma:public');
        $str = "品牌,日期,姓名,店铺,考核内容/工作内容(地名+行程主题)+同行人,下店天数,出差天数,见终端客人/老板娘,成交终端客人/老板娘,终端销售业绩,收款业绩,出货业绩,考核过关人数/加微信,卖卡数量/拜访数量,会议铺垫/收集资料,备注\n";
        echo $str;
        $emm=2;
        $emk=2;
        $bm=2;
        $bk=2;
        $i=2;
        $SUM=array();
        $count = 1000;
        $offset = 0;
        $emname = '';
        $bname = '';
        $result = $this->M_summary->getemAllSummary($count,$offset);
        while($result['row']>0) {
          $result = $this->M_summary->getemAllSummary($count,$offset);
          foreach ($result['result'] as $shop) {
            $flagemname = 0;
            //员工合计
            if($emname=='')$emname=$shop['emname'];
            if($bname=='')$bname=$shop['bname'];
            if($emname!=$shop['emname']){
              $SUM[$i]=$i;
              $emm--;
              $str = "".$bname.",合计,".$emname.", , ,=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                      "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                      "=SUM(O".$emk.":O".$emm."), \n";
              echo $str;
              $i++;
              $emm+=2;
              $emk=$emm;
              $emname = $shop['emname'];
            }
            //品牌总计
            if($bname!=$shop['bname']){
              if($flagemname == 0){
                $SUM[$i]=$i;
                $emm--;
                $str = "".$bname.",合计,".$emname.", , ,=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                        "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                        "=SUM(O".$emk.":O".$emm."), \n";
                echo $str;
                $i++;
                $emm+=2;
                $emk=$emm;
                $emname = $shop['emname'];
                $flagemname = 1;
              }
              $str = " ,总计, , , ,=SUM(".$this->Util->CsvSum("F",$SUM)."),=SUM(".$this->Util->CsvSum("G",$SUM)."),=SUM(".$this->Util->CsvSum("H",$SUM)."),=SUM(".$this->Util->CsvSum("I",$SUM)."),".
                      "=SUM(".$this->Util->CsvSum("J",$SUM)."),=SUM(".$this->Util->CsvSum("K",$SUM)."),=SUM(".$this->Util->CsvSum("L",$SUM)."),=SUM(".$this->Util->CsvSum("M",$SUM)."),=SUM(".$this->Util->CsvSum("N",$SUM)."),".
                      "=SUM(".$this->Util->CsvSum("O",$SUM)."), \n";
              echo $str;
              $i++;
              $emm++;
              $emk++;
              $SUM=array();
              $bname = $shop['bname'];
            }
            $emm++;
            $str = $shop['bname'].",".$shop['addday'].",".$shop['emname'].",".$shop['shopname'].",".$shop['content'].",".$shop['inshop'].",".
                    $shop['outday'].",".$shop['seeboss'].",".$shop['getboss'].",".$shop['tecount'].",".$shop['skcount'].",".$shop['outcount'].",".
                    $shop['joinv'].",".$shop['sellcar'].",".$shop['meet'].",".$shop['pass']."\n";
            echo $str;
            $i++;
          }
          $offset +=$count;
        }
        if($i!=2){
          $emm--;
          $SUM[$i]=$i;
          $str = "".$bname.",合计,".$emname.", , ,=SUM(F".$emk.":F".$emm."),=SUM(G".$emk.":G".$emm."),=SUM(H".$emk.":H".$emm."),=SUM(I".$emk.":I".$emm."),".
                  "=SUM(J".$emk.":J".$emm."),=SUM(K".$emk.":K".$emm."),=SUM(L".$emk.":L".$emm."),=SUM(M".$emk.":M".$emm."),=SUM(N".$emk.":N".$emm."),".
                  "=SUM(O".$emk.":O".$emm."), \n";
          echo $str;
          $str = " ,总计, , , ,=SUM(".$this->Util->CsvSum("F",$SUM)."),=SUM(".$this->Util->CsvSum("G",$SUM)."),=SUM(".$this->Util->CsvSum("H",$SUM)."),=SUM(".$this->Util->CsvSum("I",$SUM)."),".
                  "=SUM(".$this->Util->CsvSum("J",$SUM)."),=SUM(".$this->Util->CsvSum("K",$SUM)."),=SUM(".$this->Util->CsvSum("L",$SUM)."),=SUM(".$this->Util->CsvSum("M",$SUM)."),=SUM(".$this->Util->CsvSum("N",$SUM)."),".
                  "=SUM(".$this->Util->CsvSum("O",$SUM)."), \n";
          echo $str;
        }
        return false;
      }

}
